﻿// 
//    Copyright 2010 The JaernCloud Project
// 
//    Licensed under the Apache License, Version 2.0 (the "License");
//    you may not use this file except in compliance with the License.
//    You may obtain a copy of the License at
// 
//        http://www.apache.org/licenses/LICENSE-2.0
// 
//    Unless required by applicable law or agreed to in writing, software
//    distributed under the License is distributed on an "AS IS" BASIS,
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//    See the License for the specific language governing permissions and
//    limitations under the License.
// 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace JaernCloud.Language.Compiler.Ast {

    public class AstInheritsFrom : AstTokenInfo {

        public AstTagSelector TagSelector { get; set; }

        public string StringValue { get; set; }

        public int IntegerValue { get; set; }

        public float FloatValue { get; set; }

        public double DoubleValue { get; set; }

        public AstConstantValueKind? ConstantKind { get; private set; }

        public AstConstant Constant { get; set; }

        public AstInheritsFrom(AstConstantValueKind constantKind) {
            this.ConstantKind = constantKind;
        }

        public AstInheritsFrom(AstTagSelector tagSelector) {
            this.TagSelector = tagSelector;
            this.ConstantKind = null;
        }

        public AstInheritsFrom(AstTag tag) {
            this.TagSelector = new AstTagSelector(tag);
            this.ConstantKind = null;
        }

        public AstInheritsFrom(String stringValue) {
            this.StringValue = stringValue;
            this.ConstantKind = AstConstantValueKind.String;
        }

        public AstInheritsFrom(int intValue) {
            this.IntegerValue = intValue;
            this.ConstantKind = AstConstantValueKind.Integer;
        }

        public AstInheritsFrom(float floatValue) {
            this.FloatValue = floatValue;
            this.ConstantKind = AstConstantValueKind.Float;
        }

        public AstInheritsFrom(double doubleValue) {
            this.DoubleValue = doubleValue;
            this.ConstantKind = AstConstantValueKind.Double;
        }

        public AstInheritsFrom(AstConstant constant) {
            this.Constant = constant;
            this.ConstantKind = AstConstantValueKind.Constant;
        }

        public override string ToString() {
            if (ConstantKind.HasValue) {
                switch (ConstantKind.Value) {
                    case AstConstantValueKind.Constant:
                        return Constant.ToString().ToLower();
                    case AstConstantValueKind.Double:
                        return Convert.ToString(DoubleValue);
                    case AstConstantValueKind.Float:
                        return Convert.ToString(FloatValue);
                    case AstConstantValueKind.Integer:
                        return Convert.ToString(IntegerValue);
                    case AstConstantValueKind.String:
                        return StringValue;
                }
            } else if(TagSelector != null) {
                return TagSelector.ToString();
            }
            return String.Empty;
        }

    }

}
